Private Sub cmdStampa_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdStampa.Click
txtStampa.Text = UCase(txtStampa.Text)
lblOk.Text = ""
AddHandler pd.PrintPage, AddressOf Me.pd_PrintElenco
If lstSomma.Items.Count <> 0 Then
If txtStampa.Text <> "" Then
Try
AddHandler pd.PrintPage, AddressOf Me.pd_PrintElenco
pd.Print()
Catch ex As Exception
MessageBox.Show(ex.Message & Environment.NewLine & ex.StackTrace)
End Try
lblOk.Text = "OK"
Else
If MsgBox("La stampa è senza titolo, continuare?", MsgBoxStyle.YesNo, "CONTINUARE STAMPA?") = MsgBoxResult.Yes Then
Try
AddHandler pd.PrintPage, AddressOf Me.pd_PrintElenco
pd.Print()
Catch ex As Exception
MessageBox.Show(ex.Message & Environment.NewLine & ex.StackTrace)
End Try
lblOk.Text = "OK"
End If
End If
Else
MsgBox("Nessuna battuta da stampare", MsgBoxStyle.Information, "BATTUTE INESISTENTI")
txtNum.Select()
End If
End Sub
Private Sub pd_PrintElenco(ByVal sender As Object, ByVal ev As PrintPageEventArgs)
Dim printFont As New Font("Arial", 13)
Dim yPos As Long = 30
Dim xPos As Long = 30
ev.Graphics.DrawString(txtStampa.Text, printFont, Brushes.Black, xPos, yPos, New StringFormat())
yPos = yPos + Font.Height
yPos = yPos + Font.Height
printFont = New Font("Arial", 11)
Try
For x As Integer = 0 To lstSomma.Items.Count - 1
ev.Graphics.DrawString(lstSomma.Items(x).ToString, printFont, Brushes.Black, xPos, yPos, New StringFormat())
yPos = yPos + Font.Height
Next
yPos = yPos + Font.Height
yPos = yPos + Font.Height
ev.Graphics.DrawString("Totale €: " + lblSomma.Text, printFont, Brushes.Black, xPos, yPos, New StringFormat())
yPos = yPos + Font.Height
ev.Graphics.DrawString("Numero battute: " + lblBatt.Text, printFont, Brushes.Black, xPos, yPos, New StringFormat())
yPos = yPos + Font.Height
ev.Graphics.DrawString("Data e ora di stampa: " & Today & " - " & TimeOfDay, printFont, Brushes.Black, xPos, yPos, New StringFormat())
Catch ex As Exception
MessageBox.Show(ex.Message & Environment.NewLine & ex.StackTrace)
End Try
End Sub